package cn.stylefeng.guns.modular.ry600.controller;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.stylefeng.guns.core.log.LogObjectHolder;
import cn.stylefeng.guns.modular.ry600.service.ICheckService;
import cn.stylefeng.guns.modular.system.model.Check;
import cn.stylefeng.roses.core.base.controller.BaseController;

/**
 * 项目验证管理控制器
 *
 * @author fengshuonan
 * @Date 2019-01-02 17:59:24
 */
@Controller
@RequestMapping("/check")
public class CheckController extends BaseController {

    private String PREFIX = "/ry600/check/";

    @Autowired
    private ICheckService checkService;

    /**
     * 跳转到项目验证管理首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "check.html";
    }

    /**
     * 跳转到添加项目验证管理
     */
    @RequestMapping("/check_add")
    public String checkAdd() {
        return PREFIX + "check_add.html";
    }

    /**
     * 跳转到修改项目验证管理
     */
    @RequestMapping("/check_update/{checkId}")
    public String checkUpdate(@PathVariable Integer checkId, Model model) {
        Check check = checkService.selectById(checkId);
        model.addAttribute("item",check);
        LogObjectHolder.me().set(check);
        return PREFIX + "check_edit.html";
    }

    /**
     * 获取项目验证管理列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
    	Map<String,Object> columnMap=new HashMap<String,Object>();
    	if(!StringUtils.isBlank(condition)){
    		columnMap.put("check_id", condition);
    	};
        return checkService.selectByMap(columnMap);
    }

    /**
     * 新增项目验证管理
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(Check check) {
        checkService.insert(check);
        return SUCCESS_TIP;
    }

    /**
     * 删除项目验证管理
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer checkId) {
        checkService.deleteById(checkId);
        return SUCCESS_TIP;
    }

    /**
     * 修改项目验证管理
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(Check check) {
        checkService.updateById(check);
        return SUCCESS_TIP;
    }

    /**
     * 项目验证管理详情
     */
    @RequestMapping(value = "/detail/{checkId}")
    @ResponseBody
    public Object detail(@PathVariable("checkId") Integer checkId) {
        return checkService.selectById(checkId);
    }
}
